package org.example.j1110nm2;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class Login {
    @RequestMapping("/check")
    public Boolean check(String username, String password, HttpSession session){
//        if(username==null||"".equals(username)||password==null||"".equals(password)){
//            return false;
//        }

        //下面的这个就是检验我们的账号和密码是不是空的
        if(!StringUtils.hasLength(username)||!StringUtils.hasLength(password)){
            return false;
        }
        //校验我们的这个输入是不是正确的
        if("zhangsan".equals(username)&&"123456".equals(password)){
            session.setAttribute("username",username);
            return true;
        }
        return false;
    }


    @RequestMapping("/index")
    public String index(HttpSession session){
        String username = (String)session.getAttribute("username");
        return username;
    }
}
